package app.esb.hcartoon;

import app.common.dao.Leo_galcan_nameBean;
import app.esb.BaseExcutor;
import cn.lily.com.container.data.Record;
import cn.lily.com.db.DBFactory;
import cn.lily.com.db.container.reader.DataTable;
import cn.lily.com.db.sql.DBManager;
import cn.lily.com.lang.Basic;
import cn.lily.com.lang.BusinessDate;
/**
 * 里番执行类
 * @author JiaJ
 * @date 2018年2月5日
 *
 */
public class HCartoonExcutor extends BaseExcutor {
	
	 /**
	  * 插入名称
	  * @param name
	  * @param can_id
	  */
	 public static void insertCartoonNames(String names,String canID){
		 
		 if(names == null || "".equals(names)){
			 return;
		 }else{
			 
			 String[] nameAs = Basic.split(names, ",");
			 
			 for(String nameA:nameAs){
				 
				 String name_id = getDBSequence().getBussSeq("leo_can_name", 8);
				 
				 Leo_galcan_nameBean nameBean = new Leo_galcan_nameBean();
				 
				 nameBean.setCan_id(canID);
				 nameBean.setCan_name_id(name_id);
				 nameBean.setCan_name_fix(nameA);
				 nameBean.setCan_create_oper("9999");
				 nameBean.setCan_create_time(BusinessDate.getTodaytime());
				 
				 nameBean.insert();
				 
			 }
		 }
	
	 }
	
	 /**
	  * 校验名称是否存在
	  * @param name
	  * @return
	  */
	 public static boolean checkCartoonName(Record record){
		 
		 //名称处理
		 String nameAll = record.getString("CAN_NAME");
		 String nameEng = record.getString("CAN_NAM_ENG");
		 String nameJap = record.getString("CAN_NAM_JAP");
		 
		 if(nameEng != null && !"".equals(nameEng)){
			 nameAll += ","+ nameEng;
		 }
		 
		 if(nameJap != null && !"".equals(nameJap)){
			 nameAll += ","+ nameJap;
		 }
		 
		 nameAll = "'" + nameAll.replaceAll(",", "','") + "'";
		 
		 DBManager dbManager = DBFactory.getActionDB();
		 
		 DataTable dt = dbManager.executeQueryTable("select count(*) ASCOUNT from ${schema}.LEO_GALCAN_NAME where CAN_NAME_FIX in ("+nameAll+") ");
		 
		 dt.next();
		 int count = dt.getInt("ASCOUNT");
		 	 
		 if(count > 0){
			 return true;
		 }
		 else{
			 return false;
		 }
		 
	 }
	 
	 /**
	  * 获取其他名称
	  * @param record
	  * @return
	  */
	 public static String getCartoonOtherName(Record record){
		 
		 //名称处理
		 String nameOther = "";
		 String nameEng = record.getString("CAN_NAM_ENG");
		 String nameJap = record.getString("CAN_NAM_JAP");
		 
		 if(nameEng != null && !"".equals(nameEng)){

			 nameOther = nameEng;
		 }
		 
		 if(nameJap != null && !"".equals(nameJap)){
			 if(!"".equals(nameOther)){
				 nameOther += "," + nameJap;
			 }else{
				 nameOther = nameJap;
			 }
		 }
		 
		 return nameOther;
	 }
	 
	 /**
	  * 获取总名称
	  * @param record
	  * @return
	  */
	 public static String getCartoonAllName(Record record){
		 
		 //名称处理
		 String nameAll = record.getString("CAN_NAME");
		 String nameEng = record.getString("CAN_NAM_ENG");
		 String nameJap = record.getString("CAN_NAM_JAP");
		 
		 if(nameEng != null && !"".equals(nameEng)){
			 nameAll += ","+ nameEng;
		 }
		 
		 if(nameJap != null && !"".equals(nameJap)){
			 nameAll += ","+ nameJap;
		 }
		 
		 return nameAll;
		 
	 }
	 
	/**
	 * 获取厂商名称
	 * @param canID
	 * @return
	 */
	public static String getCartoonFirms(String canID){
		String sql = "select * from ${schema}.LEO_GALCAN_DETAIL_INFO where CAN_ID='"+canID+"'";
		DataTable dt = DBFactory.getActionDB().executeQueryTable(sql);
		
		if(dt.next()){
			return dt.getString("CAN_FIRM_MEMO");
		}else{
			return "";
		}		
	}
	
	/**
	 * 获取动漫简介信息 - 主表
	 * @param canID
	 * @return
	 */
	public static String getCartoonMemos(String canID){
		String sql = "select * from ${schema}.LEO_GALCAN_INFO where CAN_ID='"+canID+"'";
		DataTable dt = DBFactory.getActionDB().executeQueryTable(sql);
		
		if(dt.next()){
			return dt.getString("CAN_DEMO");
		}else{
			return "";
		}		
	}
	
}
